<?php

namespace yiike\company\backend\controllers;
use yii\helpers\Url;
use dmstr\bootstrap\Tabs;
/**
* This is the class for controller "TtycCompanyController".
*/
class TtycCompanyController extends \yiike\company\backend\controllers\base\TtycCompanyController
{

    public function actionView()
    {
        $id = \Yii::$app->user->identity->id;
        \Yii::$app->session['__crudReturnUrl'] = Url::previous();
        Url::remember();
        Tabs::rememberActiveState();

        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }
    public function actionInfo()
    {
        $id = \Yii::$app->user->identity->id;
        \Yii::$app->session['__crudReturnUrl'] = Url::previous();
        Url::remember();
        Tabs::rememberActiveState();
        $connection  = \Yii::$app->db;
        $sql     = "select count(id) as num  from ims_ttyc_stores where company_id=$id  ";
        $command = $connection->createCommand($sql);
        $stores     = $command->queryOne()['num'];

        $sql = "select count(id) as num  from ims_ttyc_maker where company_id=$id  ";
        $command = $connection->createCommand($sql);
        $makers     = $command->queryOne()['num'];
        $date = date('Ymd');

        $sql = "select sum(real_pay) as total  from ims_ttyc_stores_order where company_id=$id and date={$date} and is_pay=1";

        $command = $connection->createCommand($sql);
        $total     = $command->queryOne()['total'];
        $total = $total ? $total:0;
        return $this->render('info', [
            'model' => $this->findModel($id),
            'stores'=>$stores,
            'maker'=>$makers,
            'total'=>$total
        ]);
    }
}
